package utils

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

func NewData(ctx *gin.Context, data interface{}) {
	re := SuccessData{
		SuccessMsg: SuccessMsg{
			Success: Success{
				Code:   http.StatusOK,
				Status: "ok",
			},
		},
		Data: data,
	}
	ctx.JSON(http.StatusOK, re)
}
func NewSuccessMsg(ctx *gin.Context, msg string) {
	re := SuccessMsg{
		Success: Success{
			Code:   http.StatusOK,
			Status: "ok",
		},
		Message: msg,
	}
	ctx.JSON(http.StatusOK, re)
}
func NewSuccessMsgWithData(ctx *gin.Context, msg string, data interface{}) {
	re := SuccessData{
		SuccessMsg: SuccessMsg{
			Success: Success{
				Code:   http.StatusOK,
				Status: "ok",
			},
			Message: msg,
		},
		Data: data,
	}
	ctx.JSON(http.StatusOK, re)
}
func NewErrorMsg(ctx *gin.Context, msg string) {
	re := SuccessMsg{
		Success: Success{
			Code:   http.StatusOK,
			Status: "err",
		},
		Message: msg,
	}
	ctx.JSON(http.StatusOK, re)
}

// HTTPError example
type HTTPError struct {
	Status  string `json:"status" example:"err"`
	Code    int    `json:"code" example:"400"`
	Message string `json:"message" example:"status bad request"`
}

type Success struct {
	Code   int    `json:"code" example:"200"`
	Status string `json:"status" example:"ok"`
}

type SuccessMsg struct {
	Success
	Message string `json:"message" example:"操作成功"`
}

type SuccessData struct {
	SuccessMsg
	Data interface{} `json:"data"`
}
